<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
    <head>
        <title>发布普通运价</title>
    </head>
    <body>
        <div id="form-ct-itemselector">
        </div>
        <script>
            Ext.onReady(function(){
                /*
                 * Ext.ux.ItemSelector Example Code
                 */
                Ext.form.Field.prototype.msgTarget = 'side';
                tabs.getItem(0).setTitle('特殊舱位编辑');
                var airways = new Ext.form.ComboBox({
                    store: new Ext.data.Store({
                        proxy: new Ext.data.HttpProxy({
                            url: '/admin/getInternalAirways'
                        }),
                        reader: new Ext.data.JsonReader({
                            root: 'root',
                            id: 'id'
                        }, ['id', 'airways_name'])
                    }),
                    name: 'airways',
                    loadingText: '正在加载...',
                    displayField: 'airways_name',
                    valueField: 'id',
                    mode: 'remote',
                    triggerAction: 'all',
                    hiddenName: 'airways_id',
                    fieldLabel: "<span class='red'>*</span>空港名称",
                    emptyText: '请选择航空公司...',
                    editable: false,
                    allowBlank: false,
                    width: 130,
                    maxHeight: 150,
                    tabIndex: 4
                });
				
				var airportTpl = new Ext.XTemplate('<tpl for="."><div class="search-item">', '{airport_name}({airport_code})', '</div></tpl>');
                var airportFrom = new Ext.form.ComboBox({
                    store: new Ext.data.Store({
                        proxy: new Ext.data.HttpProxy({
                            url: "/admin/getAllAirportComboBox"
                        }),
                        reader: new Ext.data.JsonReader({
                            root: 'root'
                        }, [{
                            name: 'id'
                        }, {
                            name: 'airport_name'
                        }, {
                            name: 'airport_code'
                        }])
                    }),
                    fieldLabel: "<span class='red'>*</span>始发城市",
                    name: 'airport_from',
                    allowBlank: false,
                    blankText: "始发城市必须选择",
                    emptyText: '拼音首字母/代码',
                    typeAhead: false,
                    loadingText: '正在查找...',
                    hideTrigger: false,
                    tpl: airportTpl,
                    minChars: 0,
                    itemSelector: 'div.search-item',
                    onSelect: function(record){
                        airportFrom.setValue(record.data.airport_name);
                        from = record.data.airport_code;
                        if (this.isExpanded()) {
                            this.collapse();
                        }
                    }
                });
				
                var flights = new Ext.form.TextField({
                    fieldLabel: '适用航班',
                    //allowBlank: false,
                    name: 'flights',
                    anchor: '90%'
                });
                
                var position = new Ext.form.ComboBox({ //combobox   
                    name: 'position',
                    fieldLabel: '<span class="red">*</span>适用舱位',
                    width: '80',
                    resiable: true,
                    typeAhead: true,
                    allowBlank: false,
                    handleHeight: 100, //   
                    displayField: 'key',
                    valueField: 'value',
                    selectOnFocus: true,
                    mode: 'local',
                    selectOnFocus: true,
                    triggerAction: 'all',//这个属性非常重要,可以在选择一个值以后,依然还显示其它的值.
                    readOnly: true,
                    emptyText: '请选择舱位...',
                    store: new Ext.data.Store({
                        data: [['A', 'A'], ['B', 'B'], ['C', 'C'], ['D', 'D'], ['E', 'E'], ['F', 'F'], ['G', 'G'], ['H', 'H'], ['I', 'I'], ['J', 'J'], ['K', 'K'], ['L', 'L'], ['M', 'M'], ['N', 'N'], ['O', 'O'], ['P', 'P'], ['Q', 'Q'], ['R', 'R'], ['S', 'S'], ['T', 'T'], ['U', 'U'], ['V', 'V'], ['W', 'W'], ['X', 'X'], ['Y', 'Y'], ['Z', 'Z']],
                        reader: new Ext.data.ArrayReader({
                            id: 0
                        }, [{
                            name: 'value'
                        }, {
                            name: 'key'
                        }])
                    }), //数据储存到这个comboBox   
                    anchor: '90%'
                });
                
                var discountFrom = new Ext.form.ComboBox({ //combobox   
                    name: 'discount_from',
                    fieldLabel: '<span class="red">*</span>折扣',
                    width: '80',
                    resiable: true,
                    typeAhead: true,
                    allowBlank: false,
                    handleHeight: 100, //   
                    displayField: 'key',
                    valueField: 'value',
                    selectOnFocus: true,
                    mode: 'local',
                    selectOnFocus: true,
                    triggerAction: 'all',//这个属性非常重要,可以在选择一个值以后,依然还显示其它的值.
                    readOnly: true,
                    emptyText: '选择类型...',
                    store: new Ext.data.Store({
                        data: [['45', '45折'], ['50', '50折'], ['55', '55折'], ['60', '60折'], ['65', '65折'], ['70', '70折'], ['75', '75折'], ['80', '80折']],
                        reader: new Ext.data.ArrayReader({
                            id: 0
                        }, [{
                            name: 'value'
                        }, {
                            name: 'key'
                        }])
                    }), //数据储存到这个comboBox   
                    anchor: '90%'
                });
                
                var rakeOff = new Ext.form.NumberField({
                    fieldLabel: '<span class="red">*</span>B客户折扣',
                    allowBlank: false,
                    name: 'rake_off',
                    anchor: '90%'
                });
                
                var dateBegin = new Ext.form.DateField({
                    fieldLabel: '<span class="red">*</span>开始日期',
                    name: 'date_begin',
                    id: 'date_begin',
                    format: 'Y-m-d', //格式化日期   
                    width: '80',
                    //disabledDays: [0,6],	//不让选择周六，周日   
                    //disabledDaysText: "周末要休息",   
                    invalidText: "您输入的日期格式不对，正确格式为2008-01-01",
                    allowBlank: false,
                    inputType: '2008-01-01',
                    anchor: '90%',
                    vtype: 'daterange',
                    endDateField: 'date_end'
                });
                var dateEnd = new Ext.form.DateField({
                    fieldLabel: '<span class="red">*</span>结束日期',
                    name: 'date_end',
                    id: 'date_end',
                    format: 'Y-m-d', //格式化日期   
                    width: '80',
                    //disabledDays: [0,6],	//不让选择周六，周日   
                    //disabledDaysText: "周末要休息",   
                    invalidText: "您输入的日期格式不对，正确格式为2008-01-01",
                    allowBlank: false,
                    inputType: '2008-01-01',
                    anchor: '90%',
                    vtype: 'daterange',
                    startDateField: 'date_begin'
                });
                //自动出票
                var autoReleaseYes = new Ext.form.Radio({
                    fieldLabel: '自动出票',
                    name: 'auto_release',
                    id: 'auto_release_yes',
                    boxLabel: '是',
                    checked: true,
                    inputValue: '1'
                });
                var autoReleaseNo = new Ext.form.Radio({
                    name: 'auto_release',
                    id: 'auto_release_no',
                    boxLabel: '否',
                    checked: false,
                    hideLabel: true,
                    inputValue: '0'
                });
                //启用运价
                var isReleasedYes = new Ext.form.Radio({
                    fieldLabel: '启用运价',
                    name: 'is_released',
                    id: 'is_released_yes',
                    boxLabel: '是',
                    checked: true,
                    inputValue: '1'
                });
                var isReleasedNo = new Ext.form.Radio({
                    name: 'is_released',
                    id: 'is_released_no',
                    boxLabel: '否',
                    checked: false,
                    hideLabel: true,
                    inputValue: '0'
                });
                //客票类型
                var ticketPTBSP = new Ext.form.Radio({
                    fieldLabel: '客票类型',
                    name: 'ticket_payment_type',
                    id: 'tpt_bsp',
                    boxLabel: 'BSP',
                    checked: true,
                    inputValue: '1'
                });
                var ticketPTB2B = new Ext.form.Radio({
                    name: 'ticket_payment_type',
                    id: 'tpt_b2b',
                    boxLabel: 'B2B',
                    checked: false,
                    hideLabel: true,
                    inputValue: '0'
                });
                //转换PNR
                var cPNRYes = new Ext.form.Radio({
                    fieldLabel: '转换PNR',
                    name: 'conversion_pnr',
                    id: 'conversion_pnr_yes',
                    boxLabel: '是',
                    checked: true,
                    inputValue: '1'
                });
                var cPNRNo = new Ext.form.Radio({
                    name: 'conversion_pnr',
                    id: 'conversion_pnr_no',
                    boxLabel: '否',
                    checked: false,
                    hideLabel: true,
                    inputValue: '0'
                });
                
                var id = new Ext.form.Hidden({
                    name: 'id'
                });
                var formSpecialPosition = new Ext.form.FormPanel({
                    labelWidth: 80,
                    frame: true,
                    labelAlign: 'right',
                    width: 550,
                    url: '/ticket/save_special_position_release',
                    reader: new Ext.data.JsonReader({
                        root: 'root'
                    }, [{
                        name: 'id'
                    }, {
                        name: 'position'
                    },{
                        name: 'airport_from'
                    },{
                        name: 'discount_from'
                    }, {
                        name: 'flights'
                    }, {
                        name: 'rake_off'
                    }, {
                        name: 'ticket_payment_type'
                    }, {
                        name: 'conversion_pnr'
                    }, {
                        name: 'auto_release'
                    }, {
                        name: 'is_released'
                    }, {
                        name: 'date_begin',
                        type: 'date',
                        dateFormat: 'Y/m/d'
                    }, {
                        name: 'date_end',
                        type: 'date',
                        dateFormat: 'Y/m/d'
                    }]),
                    items: [{
                        layout: 'column',
                        border: false,
                        items: [{
                            columnWidth: .5,
                            layout: 'form',
                            border: false,
                            items: [airways]
                        }, {
                            columnWidth: .5,
                            layout: 'form',
                            border: false,
                            items: [position]
                        }]
                    },airportFrom, {
                        xtype: "itemselector",
                        name: "airports",
                        imagePath: "/images/multi_select",
                        drawUpIcon: false,
                        drawDownIcon: false,
                        drawLeftIcon: true,
                        drawRightIcon: true,
                        drawTopIcon: false,
                        drawBotIcon: false,
                        fieldLabel: "<span class='red'>*</span>目的地选择",
                        dataFields: ["code", "desc"],
                        //fromData: [[123, "One Hundred Twenty Three"], ["1", "One"], ["2", "Two"], ["3", "Three"], ["4", "Four"], ["5", "Five"], ["6", "Six"], ["7", "Seven"], ["8", "Eight"], ["9", "Nine"]],
                        fromData: <%=@airports_arraystr%>,
                        toData: <%=@airports_selected_arraystr%>,
                        msWidth: 180,
                        msHeight: 300,
                        valueField: "code",
                        displayField: "desc",
                        //imagePath:"ext-ux/multiselect",
                        //switchToFrom:true,
                        toLegend: "已经选择的城市",
                        fromLegend: "可选城市",
                        toTBar: [{
                            text: "清除",
                            handler: function(){
                                var i = formSpecialPosition.getForm().findField("airports");
                                i.reset.call(i);
                            }
                        }]
                    }, flights, dateBegin, dateEnd, {
                        layout: 'column',
                        border: false,
                        items: [{
                            columnWidth: .5,
                            layout: 'form',
                            border: false,
                            items: [dateBegin]
                        }, {
                            columnWidth: .5,
                            layout: 'form',
                            border: false,
                            items: [dateEnd]
                        }]
                    }, {
                        layout: 'column',
                        border: false,
                        items: [{
                            columnWidth: .5,
                            layout: 'form',
                            border: false,
                            items: [discountFrom]
                        }, {
                            columnWidth: .5,
                            layout: 'form',
                            border: false,
                            items: [rakeOff]
                        }]
                    }, {
                        layout: 'column',
                        border: false,
                        items: [{
                            columnWidth: .25,
                            layout: 'form',
                            border: false,
                            items: [autoReleaseYes]
                        }, {
                            columnWidth: .25,
                            layout: 'form',
                            border: false,
                            items: [autoReleaseNo]
                        }, {
                            columnWidth: .25,
                            layout: 'form',
                            border: false,
                            items: [isReleasedYes]
                        }, {
                            columnWidth: .25,
                            layout: 'form',
                            border: false,
                            items: [isReleasedNo]
                        }]
                    }, {
                        layout: 'column',
                        border: false,
                        items: [{
                            columnWidth: .25,
                            layout: 'form',
                            border: false,
                            items: [ticketPTBSP]
                        }, {
                            columnWidth: .25,
                            layout: 'form',
                            border: false,
                            items: [ticketPTB2B]
                        }, {
                            columnWidth: .25,
                            layout: 'form',
                            border: false,
                            items: [cPNRYes]
                        }, {
                            columnWidth: .25,
                            layout: 'form',
                            border: false,
                            items: [cPNRNo]
                        }]
                    }, id],
                    buttons: [{
                        text: '确定',
                        handler: onItemClick //实际应用一般是处理fp.getForm.submit()事件   
                    }, {
                        text: '重置',
                        handler: function(){
                            formSpecialPosition.getForm().reset();
                        }
                    }, {
                        text: '帮助',
                        handler: function(){
                            formSpecialPosition.getForm().reset();
                        }
                    }]
                });
                //, flights, airwaysname, discountFrom, discountTo, dateBegin, dateEnd,isReleased,rakeOff,ticketPaymentType
                formSpecialPosition.render("form-ct-itemselector");
                function onItemClick(item){
                    if (formSpecialPosition.form.isValid()) {
                        formSpecialPosition.form.submit({
                            waitMsg: 'In processing',
                            success: function(form, action){
                                Ext.MessageBox.alert("提示", "特殊舱位添加成功！");
                                tabs.getActiveTab().getUpdater().update("/ticket/special_position_released_list");
                            },
                            failure: function(form, action){
                                Ext.MessageBox.alert('提交错误消息', '提交失败');
                            }
                        });
                    }
                    else {
                        Ext.MessageBox.alert("提示", "请按要求填写带<span class='red'>*</span>的必输值！");
                    }
                }
                // load form and assign value to fields
                formSpecialPosition.form.load({
                    url: '/ticket/getSpecialPositionByID?id=<%=params[:id]%>',
                    waitMsg: '正在载入数据...',
                    success: function(form, action){
                        airways.setRawValue(form.reader.jsonData.root[0].airways.airways_name);
                    },
                    failure: function(form, action){
                        Ext.MessageBox.alert('提示信息', '信息加载失败');
                    }
                });
            })
        </script>
    </body>
</html>
